package cn.itfei.lottery.domain.rule.service.logic;


import cn.itfei.lottery.common.Constants;
import cn.itfei.lottery.domain.rule.model.req.DecisionMatterReq;
import cn.itfei.lottery.domain.rule.model.vo.TreeNodeLineVO;

import java.util.List;

/**
 * @description:    规则基础抽象类
 * @author：hfb
 * @date: 2023/11/16
 */
public abstract class BaseLogic implements LogicFilter{


    @Override
    public Long filter(String matterValue, List<TreeNodeLineVO> treeNodeLineInfoList) {
        for (TreeNodeLineVO nodeLine : treeNodeLineInfoList) {
            if (decisionLogic(matterValue, nodeLine)) {
                return nodeLine.getNodeIdTo();  // 当前传入男，取出当前节点的左右孩子信息（连线信息）按照不同连线的比较规则，是 = ，左孩子为男，右孩子为女，则按照比较规则，返回的是左孩子的节点id，
            }

        }

        return Constants.Global.TREE_NULL_NODE;
    }

    @Override
    public abstract String matterValue(DecisionMatterReq decisionMatter);

    private boolean decisionLogic(String matterValue, TreeNodeLineVO nodeLine) {
        switch (nodeLine.getRuleLimitType()) {
            case Constants.RuleLimitType.EQUAL:
                return matterValue.equals(nodeLine.getRuleLimitValue());
            case Constants.RuleLimitType.GT:
                return Double.parseDouble(matterValue) > Double.parseDouble(nodeLine.getRuleLimitValue());
            case Constants.RuleLimitType.LT:
                return Double.parseDouble(matterValue) < Double.parseDouble(nodeLine.getRuleLimitValue());
            case Constants.RuleLimitType.GE:
                return Double.parseDouble(matterValue) >= Double.parseDouble(nodeLine.getRuleLimitValue());
            case Constants.RuleLimitType.LE:
                return Double.parseDouble(matterValue) <= Double.parseDouble(nodeLine.getRuleLimitValue());
            default:
                return false;

        }
    }
}
